<?php

/**
 * 控制器基础类文件
 * @abstract 提供基础的控制器逻辑处理支持
 * @author 暮雨秋晨
 * @copyright 2014
 */

class Controller extends Template
{
    /**
     * @name success 成功提示
     * @param string $msg 提示信息
     * @param string $url 跳转地址
     * @param integer $time 等待时长
     */
    protected function success($msg = '操作成功', $url = '', $time = 5)
    {
        echo <<< HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>操作成功</title>
<style type="text/css">
*{ padding: 0; margin: 0; }
body{ background: #fff; font-family: '微软雅黑'; color: #333; font-size: 16px; max-width: 500px; margin: 0 auto; text-align: center; }
.system-message{ padding: 24px 48px; }
.system-message h1{ font-size: 100px; font-weight: normal; line-height: 120px; margin-bottom: 12px; }
.system-message .jump{ padding-top: 10px}
.system-message .jump a{ color: #333;}
.system-message .success,.system-message .error{ line-height: 1.8em; font-size: 36px }
.system-message .detail{ font-size: 12px; line-height: 20px; margin-top: 12px; display:none}
</style>
</head>
<body>
<div class="system-message">
<img src="" alt="开心~~" title="啊哈哈~~成功咯~~开心ing~~" />
<p class="success">{$msg}</p>
<p class="detail"></p>
<p class="jump">
页面自动<a id="href" href="{$url}">跳转</a>中，等待时间： <b id="wait">{$time}</b>
</p>
</div>
<script type="text/javascript">
(function(){
var wait = document.getElementById('wait'),href = document.getElementById('href').href;
var interval = setInterval(function(){
	var time = --wait.innerHTML;
	if(time <= 0) {
		location.href = href;
		clearInterval(interval);
	};
}, 1000);
})();
</script>
</body>
</html>
HTML;
        exit;
    }

    /**
     * @name error 失败提示
     * @param string $msg 提示信息
     * @param string $url 跳转地址
     * @param integer $time 等待时间
     */
    protected function error($msg = '操作失败', $url = '', $time = 5)
    {
        echo <<< HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>操作失败</title>
<style type="text/css">
*{ padding: 0; margin: 0; }
body{ background: #fff; font-family: '微软雅黑'; color: #333; font-size: 16px; max-width: 500px; margin: 0 auto; text-align: center; }
.system-message{ padding: 24px 48px; }
.system-message h1{ font-size: 100px; font-weight: normal; line-height: 120px; margin-bottom: 12px; }
.system-message .jump{ padding-top: 10px}
.system-message .jump a{ color: #333;}
.system-message .success,.system-message .error{ line-height: 1.8em; font-size: 36px }
.system-message .detail{ font-size: 12px; line-height: 20px; margin-top: 12px; display:none}
</style>
</head>
<body>
<div class="system-message">
<img src="" alt="伤心~~" title="噢~出错啦~~都是我的错~~求你原谅我~~~" />
<p class="error">{$msg}</p>
<p class="detail"></p>
<p class="jump">
页面自动<a id="href" href="{$url}">跳转</a>中，等待时间： <b id="wait">{$time}</b>
</p>
</div>
<script type="text/javascript">
(function(){
var wait = document.getElementById('wait'),href = document.getElementById('href').href;
var interval = setInterval(function(){
	var time = --wait.innerHTML;
	if(time <= 0) {
		location.href = href;
		clearInterval(interval);
	};
}, 1000);
})();
</script>
</body>
</html>
HTML;
        exit;
    }

    /**
     * @name urlCreate
     * @abstract URL创建器
     * @param string $controller 控制器
     * @param string $action 操作
     * @param array  $params 参数
     */
    protected function urlCreate($controller, $action, $params = array())
    {
        $param = '';
        if (!empty($params)) {
            foreach ($params as $key => $val) {
                $param .= '&' . $key . '=' . $val;
            }
        }
        return '/index.php?c=' . $controller . '&a=' . $action . $param;
    }
}

?>